﻿using FRMS.DAL;
using FRMS.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FRMS.BUS
{
    public class RecordBUS
    {
        public ResponseMessage QueryDeviceRecordList(DeviceRecord deviceRecord)
        {
            ResponseMessage message = new ResponseMessage();
            RecordDAL da = new RecordDAL();
            message.errcode = 0;
            message.data = da.QueryDeviceRecord(deviceRecord);
            message.total = da.QueryDeviceRecordCount(deviceRecord);

            return message;
        }

        public ResponseMessage DeleteDeviceRecord(int id)
        {
            ResponseMessage message = new ResponseMessage();
            RecordDAL da = new RecordDAL();
            bool result = da.DeleteDeviceRecord(id);
            if (result)
            {
                message.errcode = 0;
            }
            else
            {
                message.errcode = 1;
                message.errmsg = "删除设备记录失败";
            }


            return message;
        }

        public ResponseMessage QueryLadderRecoedList(LadderRecord ladderRecord)
        {
            ResponseMessage message = new ResponseMessage();
            RecordDAL da = new RecordDAL();
            message.errcode = 0;
            message.data = da.QueryLadderRecord(ladderRecord);
            message.total = da.QueryLadderRecordCount(ladderRecord);

            return message;
        }

        public ResponseMessage DeleteLadderRecord(int id)
        {
            ResponseMessage message = new ResponseMessage();
            RecordDAL da = new RecordDAL();
            bool result = da.DeleteLadderRecord(id);
            if (result)
            {
                message.errcode = 0;
            }
            else
            {
                message.errcode = 1;
                message.errmsg = "删除乘梯记录失败";
            }


            return message;
        }

        public ResponseMessage QueryWorkModeStateRecordList(WorkModeStateRecord workModeState )
        {
            ResponseMessage message = new ResponseMessage();
            RecordDAL da = new RecordDAL();
            message.errcode = 0;
            message.data = da.QueryWorkModeStateRecord(workModeState);
            message.total = da.QueryWorkModeStateRecordCount(workModeState);

            return message;
        }

        public ResponseMessage QueryControllerStateRecordList(DeviceControllerStateRecord deviceControllerState)
        {
            ResponseMessage message = new ResponseMessage();
            RecordDAL da = new RecordDAL();
            message.errcode = 0;
            message.data = da.QueryControllerStateRecord(deviceControllerState);
            message.total = da.QueryControllerStateRecordCount(deviceControllerState);

            return message;
        }

        public ResponseMessage InsertLadder(string device_uuid,string ownwe_uuid)
        {
            ResponseMessage message = new ResponseMessage();
            RecordDAL da = new RecordDAL();
            bool result = da.InsertLadderRecord(device_uuid, ownwe_uuid);
            if (result)
            {
                message.errcode = 0;
            }
            else
            {
                message.errcode = 1;
                message.errmsg = "记录新增失败";
            }
            

            return message;
        }

        public ResponseMessage DeleteLadder(string device_uuid)
        {
            ResponseMessage message = new ResponseMessage();
            RecordDAL da = new RecordDAL();
            bool result = da.DeleteLadderRecord(device_uuid);
            if (result)
            {
                message.errcode = 0;
            }
            else
            {
                message.errcode = 1;
                message.errmsg = "清除失败";
            }


            return message;
        }
    }
}
